<?php

namespace App\Http\Controllers\Api;

use App\Models\Category;
use App\Http\Controllers\Controller;

class CategoryController extends Controller
{

    public function getProducts(Category $category)
    {
        $products = $category->products->map(function ($item) {
            $item->skus->map(function ($item2) {
                $item2->type = json_decode($item2->type);
                return $item2;
            });
            return $item;
        });

        return response()->json(['code' => 1, 'data' => $products]);
    }


}
